//编辑个人信息
import React, { Component } from 'react'
import {
    View,
    Text,
    TextInput,
    TouchableOpacity,
} from 'react-native';

import { informationStyle as styles } from '../../../../styles';
import Icon from 'react-native-vector-icons/Ionicons';
import Timeutil from '../../../util/newtimeUtil';
import fmt from '../../../util/fmtDateUtil';

var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;

export default class Inf_body extends Component {

    constructor(props) {
        super(props);
        this.state = { member: {} };
    };

    componentDidUpdate() {
        if (!this.state.member.memberId && this.props.member.memberId) {
            this.setState({ member: this.props.member })
        }
    }
    render() {
        const member = this.state.member ? this.state.member : this.props.member;
        return (
            <View>
                <View style={[styles.rtopin, {
                    width: width * 1,
                    elevation: 5,
                    shadowColor: 'black',
                    shadowOpacity: 1,
                    shadowRadius: 5
                }]}>

                    <TouchableOpacity activeOpacity={1} style={styles.rtopicon1}
                        onPress={() => { this.props.navigation.goBack() }}>
                        <Icon
                            name={'ios-arrow-back'}
                            size={25}
                            color={'#ffffff'} />
                    </TouchableOpacity>

                    <Text style={styles.rtoptext}>我的信息</Text>


                    <TouchableOpacity style={styles.rtoptouch} activeOpacity={1}
                    onPress={() => {
                        const m = {
                            memberId: this.state.member.memberId,
                            loginId: this.state.member.loginId,
                            memberName: this.state.member.memberName,
                            memberSex: parseInt(this.state.member.memberSex),
                            memberAge: parseInt(this.state.member.memberAge),
                            memberBirth: fmt(this.state.member.memberBirth, 'yyyy-MM-dd'),
                            memberEducation: this.state.member.memberEducation,
                            memberIdcard: this.state.member.memberIdcard,
                            memberPicture: this.state.member.memberPicture,
                            memberPhone: this.state.member.memberPhone,
                            memberEmail: this.state.member.memberEmail,
                            memberAddress: this.state.member.memberAddress,
                            deleteMemberDate: this.state.member.deleteMemberDate,
                            deleteFalt: this.state.member.deleteFalt,
                        }
                        this.props.actions.updateMemberInfoAction(m);
                        this.props.navigation.goBack()
                    }}>
                        <Text style={styles.rtoptext2}>保存</Text>
                    </TouchableOpacity>
                </View >

                <View style={styles.rout}>
                    {/* 姓名 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>用户名</Text>
                        <TextInput
                            defaultValue={this.state.member.memberName}
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            onChangeText={this.memberName.bind(this)}
                        />

                    </View>

                    {/* 性别 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>性别</Text>
                        <View style={styles.rsex}>
                            <TouchableOpacity style={styles.rsk} activeOpacity={1} onPress={() => { this.choose(1) }}>
                                {this.state.member.memberSex == 1 ? <Text style={styles.rsk2}>
                                    <Icon
                                        name={'md-checkmark'}
                                        size={18}
                                        color={'#fff'} />
                                </Text> : <Text style={styles.rsk}></Text>}
                            </TouchableOpacity>
                            <Text style={styles.sexin}>男</Text>

                            <TouchableOpacity style={styles.rsk} activeOpacity={1} onPress={() => { this.choose(2) }}>
                                {this.state.member.memberSex == 2 ? <Text style={styles.rsk2}>
                                    <Icon
                                        name={'md-checkmark'}
                                        size={18}
                                        color={'#fff'} />
                                </Text> : <Text style={styles.rsk}></Text>}
                            </TouchableOpacity>
                            <Text style={styles.sexin2}>女</Text>
                        </View>
                    </View>

                    {/* 生日 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>生日</Text>
                        <Timeutil
                            function={this.memberBirth.bind(this)}
                            time={this.state.member.memberBirth}
                        />
                    </View>

                    {/* 年龄 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>年龄</Text>
                        <TextInput
                            defaultValue={this.num(this.state.member.memberAge)}
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            keyboardType='numeric'
                            onChangeText={this.memberAge.bind(this)}
                        />
                    </View>

                    {/* 身份证 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>身份证</Text>
                        <TextInput
                            defaultValue={this.state.member.memberIdcard}
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            onChangeText={this.memberIdcard.bind(this)}
                        />
                    </View>

                    {/* 地址 */}
                    <View style={styles.rmall}>
                        <Text style={styles.rtxt}>地址</Text>
                        <TextInput
                            defaultValue={this.state.member.memberAddress}
                            style={[styles.inputname, { width: width * 0.7 }]}
                            underlineColorAndroid="transparent"
                            onChangeText={this.memberAddress.bind(this)}
                        />
                    </View>
                </View >
            </View>
        )
    }

    choose(a) {
        const member = this.state.member;
        member.memberSex = a;
        this.setState({ member: member });
    }

    memberName(a) {
        const member = this.state.member;
        member.memberName = a;
        this.setState({ member: member });
    }

    memberBirth(a) {
        const member = this.state.member;
        member.memberBirth = a;
        this.setState({ member: member });
    }

    memberAge(a) {
        const member = this.state.member;
        member.memberAge = a;
        this.setState({ member: member });
    }

    memberIdcard(a) {
        const member = this.state.member;
        member.memberIdcard = a;
        this.setState({ member: member });
    }

    memberAddress(a) {
        const member = this.state.member;
        member.memberAddress = a;
        this.setState({ member: member });
    }

    num(a) {
        var str = '';
        if (a != undefined) {
            str = a + '';
        }
        return str;
    }
}